/*#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

typedef struct {
    char AD;
    int ID;
    int time;
}car;

typedef struct {
    car* base;
    car* top;
    int length;
}Parking_lot;
//队列，表示便道,便道里的车仅仅用编号表示
typedef struct Node{
    car data;
    struct Node* next;
}Queue_Node;

typedef struct {
    Queue_Node* front;
    Queue_Node* rear;
    int length;
}Side_Rode;

Parking_lot Init_Parking(Parking_lot* Parking,int n);
Side_Rode Init_Side_Rode(Side_Rode* side_rode);
void Enter_parking(Parking_lot* Parking,car C,int n);
car Pop_a_car_Parking(Parking_lot* cars);
car Pop_a_car_Side(Side_Rode* side_rode);
void Enter_a_car(Parking_lot* Parking,car C);
void Pop_car(Parking_lot* Parking,Side_Rode *side_rode,car C,int n);
void Enter_car_in_side(Side_Rode *side_rode,car C);
int Location_car(Parking_lot *parking,car C);
void menu();
void Location_Parking(Parking_lot* Parking);

//1.一个顺序栈模拟停车场，初步拟定停n辆车.  data包含 加入or离开 车牌号 到达时间or离开时间
//2.若进入，输出在停车场或者便道的位置
//3.若离开，输出在停车场停留的时间，写一个函数停车费用，暂定4/h停车费
//4.设定另一个栈为让道的汽车，顺序栈

int main(){
    int n=2;
    Parking_lot Parking=Init_Parking(&Parking,n);
    Side_Rode side_rode=Init_Side_Rode(&side_rode);//构建便道
    *//*char AD[]={'A', 'A', 'D', 'A', 'D', 'E'};
    int ID[]={1,2,1,3,2,0};
    int time[]={5,10,15,20,35,0};
    int i=0;
    while (AD[i]!='E'){
        if(AD[i]=='A'){
            car C;
            C.AD='A';
            C.ID=ID[i];
            C.time=time[i];
            if(Parking.length<n){
                Enter_parking(&Parking,C,n);
            } else{
                Enter_car_in_side(&side_rode,C);
            }
        } else if(AD[i]=='D'){
            car C;
            C.AD='D';
            C.ID=ID[i];
            C.time=time[i];
            int k= Location_car(&Parking,C);
            Pop_car(&Parking,&side_rode,C,k);
        }
        i++;
    }*//*
    char AD[100];
    int ID;
    int time;
    int i=0;
    while (1){
        menu();
        printf("A or D: ");
        scanf_s(" %c", &AD[i]);
        if(AD[i]=='E'){
            break;
        }
        printf("ID and time:");
        scanf_s("%d %d",&ID,&time);
        if(AD[i]=='A'){
            car C;
            C.AD='A';
            C.ID=ID;
            C.time=time;
            if(Parking.length<n){
                Enter_parking(&Parking,C,n);
                Location_Parking(&Parking);
            } else{
                Enter_car_in_side(&side_rode,C);
            }
        } else if(AD[i]=='D'){
            car C;
            C.AD='D';
            C.ID=ID;
            C.time=time;
            int k= Location_car(&Parking,C);
            Pop_car(&Parking,&side_rode,C,k);
        } else{
            printf("Please select the right operation\n");
        }
    }
    return 0;
}


//创建一个停车场，创建一个顺序栈
Parking_lot Init_Parking(Parking_lot* Parking,int n){
    Parking=(Parking_lot *) malloc(n*sizeof (Parking_lot));  //给新的停车场分配内存
    if(Parking==NULL){
        printf("the Parking lot can not be founded\n");
        assert(Parking!=NULL);
    }
    Parking->base = (car*)malloc(n*sizeof(car)); // 为停车场的栈分配内存
    if (Parking->base == NULL) {
        // 处理内存分配失败的情况
        printf("Failed to allocate memory for Parking->base\n");
        assert(Parking->base != NULL);
    }
    Parking->top = Parking->base;   // 将top指针指向栈底
    Parking->length = 0;
    return *Parking;
}


void Enter_a_car(Parking_lot* Parking,car C){
    Parking->top->ID=C.ID;
    Parking->top->AD=C.AD;
    Parking->top->time=C.time;
    Parking->top++;   //栈顶指针向上移动
}

//若停车场已经满了，则入便道
void Enter_car_in_side(Side_Rode *side_rode,car C){
    Queue_Node *p=(Queue_Node*) malloc(sizeof (Queue_Node));
    if(p==NULL){
        printf("the memory allocation is failure\n");
        return;
    }
    p->data.time=C.time;
    p->data.ID=C.ID;
    p->data.AD=C.AD;
    side_rode->rear->next=p;
    side_rode->rear=p;
    side_rode->length++;
    printf("the car have successfully parked in the side rode\n");
    printf("the location of %d car in %d\n",side_rode->rear->data.ID,side_rode->length);
}

void menu(){
    printf("----------------------------------------\n");
    printf("---Please input the car's information---\n");
    printf("----------------------------------------\n");
}

void Location_Parking(Parking_lot* Parking){
    printf("the car have successfully parked in the Parking lot\n");
    printf("the location of %d car in %d\n",(Parking->top-1)->ID,Parking->length);
}

//当输入D的时候，计算对应编号在什么位置
int Location_car(Parking_lot *parking,car C){
    if(parking->top==parking->base){    //停车场没有车则退出
        printf("this Parking lot have not cars\n");
        return -1;
    }
    int count=0;
    car *p=parking->top;
    while (p->ID!=C.ID){
        count++;
        p--;
        if(count>parking->length){     //判断是否能找到对应的汽车
            printf("have not find this car\n");
            return -1;
        }
    }
    return count;
}

//创建一个便道，创建一个队列
Side_Rode Init_Side_Rode(Side_Rode* side_rode){
    side_rode->front=side_rode->rear=(Queue_Node*) malloc(sizeof (Queue_Node));
    if(side_rode->rear==NULL){
        printf("the memory allocation is failure\n");
        assert(side_rode->rear!=NULL);
    }
    side_rode->front->next=NULL;
    side_rode->length=0;
    return *side_rode;
}

car Pop_a_car_Side(Side_Rode* side_rode){
    if(side_rode->front==side_rode->rear){
        assert(side_rode->front!=side_rode->rear);
    }
    Queue_Node *p=side_rode->front->next;
    car C;
    C.AD=p->data.AD;
    C.time=p->data.time;
    C.ID=p->data.ID;
    side_rode->front->next=p->next;
    if(p==side_rode->rear){
        side_rode->rear=side_rode->front;
    }
    free(p);
    side_rode->length--;
    return C;
}

car Pop_a_car_Parking(Parking_lot* cars){   //弹出新栈中的元素
    if(cars->top==cars->base){
        printf("have not find cars\n");
        assert(cars->top!=cars->base);
    }
    --cars->top;
    car C;
    C.AD=cars->top->AD;
    C.time=cars->top->time;
    C.ID=cars->top->ID;
    return C;
}

//车辆离开停车场，数据出栈,传入离开的位置
void Pop_car(Parking_lot* Parking,Side_Rode *side_rode,car C,int n){
    if(Parking->base==Parking->top){     //判断是否有车辆
        printf("have not cars\n");
        return;
    }
    int i=n;
    Parking_lot cars=Init_Parking(&cars,n-1);  //创建一个新的栈，用于将让位的车放进去
    Parking->top--;  //将栈顶指针指向栈顶元素
    while (--i){    //先将前n-1个车开出去，开入一个新的栈里面
        car C1;
        C1.AD=Parking->top->AD;
        C1.time=Parking->top->time;
        C1.ID=Parking->top->ID;
        Enter_parking(&cars,C1,n-1);  //将前n-1个车先让出来，用一个栈储存
        Parking->top--;
    }
    printf("this %d car have parked %d hours.\n",Parking->top->ID,C.time-Parking->top->time);  //进栈的车辆的时间减去要出栈车辆的时间
    printf("the fee is %d.\n",4*(C.time-Parking->top->time));
    i=n;//直接将前n-1个辆车再次入栈
    while (--i){
        car C1= Pop_a_car_Parking(&cars);
        Enter_a_car(*(&Parking),C1);
    }
    Parking->length--;    //长度减一，意味着停车场的位置减少一个
    if(side_rode->length>0){      //判断便道是否为空，若为空，则只用管普通的进入
        car C2=Pop_a_car_Side(*(&side_rode));
        C2.time=C.time;
        Enter_a_car(*(&Parking), C2);  //将便道上的车加入停车场,并且修改便道进场的时间
        Parking->length++;          //停车场长度加一
    }
}

//车辆进入停车场,数据进栈
void Enter_parking(Parking_lot* Parking,car C,int n){
    if(Parking->length>=n){    //判断是否可以停车
        printf("the Parking lot is full\n");
        return;
    }
    Parking->top->ID=C.ID;
    Parking->top->AD=C.AD;
    Parking->top->time=C.time;
    printf("this car have parked successfully\n");
    printf("the location of %d car in %d\n",Parking->top->ID,Parking->length+1);
    Parking->top++;   //栈顶指针向上移动
    Parking->length++;

}*/
